package cn.z2huo.leetcode.problem.NO_00010;

public class Main2 {
    public static void main(String[] args){
        int[] waterArray = {1,8,6,2,5,4,8,3,7};
        int demo;
        int maxVolume = 0;
        int lowFlag = 0;
        int highFlag = waterArray.length-1;
        while (lowFlag<highFlag){
            if(maxVolume==0){
                maxVolume = (highFlag-lowFlag)*Math.min(waterArray[lowFlag],waterArray[highFlag]);
            }else {
                if(waterArray[lowFlag+1] > waterArray[lowFlag]){
                    if((demo=(highFlag-lowFlag-1)*Math.min(waterArray[lowFlag+1],waterArray[highFlag]))>maxVolume){
                        maxVolume = demo;
                    }
                }
                lowFlag++;
                if(waterArray[highFlag-1] > waterArray[highFlag]){
                    if((demo=(highFlag-lowFlag-1)*Math.min(waterArray[highFlag-1],waterArray[lowFlag]))>maxVolume){
                        maxVolume = demo;
                    }
                }
                highFlag--;
            }
        }
        System.out.println(maxVolume);
    }
}